//
//  GuestOrderDetailViewController.m
//  penzer
//
//  Created by 还带大道 on 2018/10/30.
//  Copyright © 2018年 caiyc. All rights reserved.
//

#import "GuestOrderDetailViewController.h"
#import "SPOrderDetailHeaderView.h"
#import "SPOrderListTableViewCell.h"
#import "SPOrderDetailSectionHeaderView.h"
#import "SPOrderInfoView.h"
#import "GuestOrderInfoView.h"
#import "GuestOrderBottomView.h"
#import "DeviceTool.h"

@interface GuestOrderDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation GuestOrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigation:1 andTitle:@"订单详情" andNaviColor:nil andTitleColor:nil];
    [self setupTableView];
    self.tableView.backgroundColor = [UIColor whiteColor];
    
}

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    self.tableView.tableHeaderView.height = 85;
}


- (void)setupTableView
{
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    SPOrderDetailHeaderView *headerV = [SPOrderDetailHeaderView shareHeaderView];
    self.tableView.tableHeaderView = headerV;
    
    self.tableView.tableFooterView = [UIView new];
    self.tableView.tableFooterView.height = 50;
    self.tableView.tableFooterView.backgroundColor = RZ_COLOR(240, 240, 240);
    
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([SPOrderListTableViewCell class]) bundle:nil]  forCellReuseIdentifier:NSStringFromClass([SPOrderListTableViewCell class])];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([SPOrderInfoView class]) bundle:nil] forHeaderFooterViewReuseIdentifier:NSStringFromClass([SPOrderInfoView class])];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([SPOrderDetailSectionHeaderView class]) bundle:nil] forHeaderFooterViewReuseIdentifier:NSStringFromClass([SPOrderDetailSectionHeaderView class])];
}


#pragma mark--
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return section==0?2:0;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 110;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return section==0?45:20;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return section==0?198:80;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *footerV;
    if(section == 0){
        GuestOrderInfoView *info = [GuestOrderInfoView shareHeaderView];
        footerV = info;
    }else{
       GuestOrderBottomView *bottom = [GuestOrderBottomView shareHeaderView];
        bottom.contactServiceBlock = ^{
            [self contactService];
        };
        bottom.comfirmBlock = ^{
            [self comfirm];
        };
        bottom.logisticsBlock = ^{
            [self logisticsInfo];
        };
        footerV = bottom;
    }
    return footerV;
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerV;
    if(section == 0){
        SPOrderDetailSectionHeaderView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:NSStringFromClass([SPOrderDetailSectionHeaderView class])];
        view.title.text = [NSString stringWithFormat:@"商品(%ld)",2];
        view.des.text = @"退货";
        headerV = view;
    }else{
        headerV = [UIView new];
        headerV.backgroundColor = RZ_COLOR(240, 240, 240);
    }
    
    return headerV;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SPOrderListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SPOrderListTableViewCell class])];
    return cell;
}


#pragma mark--联系客服
- (void)contactService
{
    RZLog(@"联系客服");
    [DeviceTool shareInstance].target = self;
    [[DeviceTool shareInstance] callWithPhoneNumber:@"123456789"];
}

#pragma mark--确认收货
- (void)comfirm
{
    RZLog(@"确认收货");
}
#pragma mark--物流信息
- (void)logisticsInfo
{
    RZLog(@"物流信息");
}
@end
